home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_emacs.idb / usr / freeware / info / ccmode-1.z / ccmode-1
Encoding:
GNU Info File  |  1998-10-28  |  46.3 KB  |  1,202 lines

  1. This is Info file ../info/ccmode, produced by Makeinfo-1.63 from the
  2. input file cc-mode.texi.
  3.  
  4.    Copyright (C) 1995 Free Software Foundation, Inc.
  5.  
  6. 
  7. File: ccmode,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)
  8.  
  9. * Menu:
  10.  
  11. * Introduction::
  12. * Getting Connected::
  13. * New Indentation Engine::
  14. * Minor Modes::
  15. * Indentation Commands::
  16. * Customizing Indentation::
  17. * Syntactic Symbols::
  18. * Performance Issues::
  19. * Frequently Asked Questions::
  20. * Getting the latest cc-mode release::
  21. * Sample .emacs File::
  22. * Requirements::
  23. * Limitations and Known Bugs::
  24. * Mailing Lists and Submitting Bug Reports::
  25. * Concept Index::
  26. * Command Index::               Command Index
  27. * Key Index::                   Key Index
  28. * Variable Index::              Variable Index
  29.  
  30. 
  31. File: ccmode,  Node: Introduction,  Next: Getting Connected,  Prev: Top,  Up: Top
  32.  
  33. Introduction
  34. ************
  35.  
  36.    Welcome to `cc-mode', version 4.  This is a GNU Emacs mode for
  37. editing files containing C, C++, Objective-C, and Java code.  This
  38. incarnation of the mode is descendant from `c-mode.el' (also called
  39. "Boring Old C Mode" or BOCM `:-)', and `c++-mode.el' version 2, which I
  40. have been maintaining since 1992.  `cc-mode' represents a significant
  41. milestone in the mode's life.  It has been fully merged back with Emacs
  42. 19's `c-mode.el'. Also a new, more intuitive and flexible mechanism for
  43. controlling indentation has been developed.
  44.  
  45.    `cc-mode' version 4 supports the editing of K&R and ANSI C, "ARM"
  46. (1) C++, Objective-C, and Java files.  In this way, you can easily set
  47. up consistent coding styles for use in editing all C, C++, Objective-C,
  48. and Java programs.
  49.  
  50.    This manual will describe the following:
  51.  
  52.    * How to get started using `cc-mode'.
  53.  
  54.    * How the new indentation engine works.
  55.  
  56.    * How to customize the new indentation engine.
  57.  
  58.    Note that the name of this file is `cc-mode.el', and I'll often
  59. refer to the package as `cc-mode', but there really is no top level
  60. `cc-mode' entry point.  I call it `cc-mode' simply to differentiate it
  61. from `c-mode.el'.  All of the variables, commands, and functions in
  62. `cc-mode' are prefixed with `c-<thing>', and `c-mode', `c++-mode',
  63. `objc-mode', and `java-mode' entry points are provided.  This file is
  64. intended to be a replacement for `c-mode.el' and `c++-mode.el'.
  65.  
  66.    The major version number was incremented to 4 with the addition of
  67. `objc-mode'. To find the minor revision number of this release, use
  68. `M-x c-version RET'.  Work has already begun on `cc-mode' version 5, in
  69. which Emacs 18 will not be supported.
  70.  
  71.    As of this writing (19-Jan-1996), both Emacs 19.30 and XEmacs 19.13
  72. are distributed with `cc-mode'.  Emacs 19.31 and XEmacs 19.14 will both
  73. contain the latest version of cc-mode when it is released.  If you are
  74. running older versions of these Emacsen, you may want to upgrade your
  75. copy of `cc-mode'.  See *Note Getting the latest cc-mode release::.
  76.  
  77.    This distribution also contains a file called `cc-compat.el' which
  78. should ease your transition from BOCM to `cc-mode'.  It currently comes
  79. unguaranteed and unsupported, but this may change for future versions.
  80.  
  81.    A special word of thanks goes to Krishna Padmasola for his work in
  82. converting the original `README' file to texinfo format.  `cc-mode'
  83. users have been clamoring for a manual for a long time, and thanks to
  84. Krishna, it is now available <clap> <clap> <clap>!  `:-)'
  85.  
  86.    ---------- Footnotes ----------
  87.  
  88.    (1)  i.e. "The Annotated C++ Reference Manual", by Ellis and
  89. Stroustrup.
  90.  
  91. 
  92. File: ccmode,  Node: Getting Connected,  Next: New Indentation Engine,  Prev: Introduction,  Up: Top
  93.  
  94. Getting Connected
  95. *****************
  96.  
  97.    `cc-mode.el' works well with the 2 main branches of Emacs 19: XEmacs
  98. and the Emacs 19 maintained by the FSF.  Emacs 19 users will want to
  99. use Emacs version 19.21 or better, XEmacs users will want 19.6 or
  100. better.  Earlier versions of these Emacsen have deficiencies and/or bugs
  101. which will adversely affect the performance and usability of `cc-mode'.
  102.  
  103.    Similarly if you use the `cc-mode-18.el' compatibility file,
  104. `cc-mode.el' will work with Emacs 18, but only moderately well.  A word
  105. of warning though, *Emacs 18 lacks some fundamental functionality and
  106. that ultimately means using Emacs 18 is a losing battle*.  Hence
  107. `cc-mode' under Emacs 18 is no longer supported and it is highly
  108. recommended that you upgrade to Emacs 19.  If you use `cc-mode' under
  109. Emacs 18, you're on your own.  With `cc-mode' version 5, Emacs 18
  110. support will be dropped altogether.
  111.  
  112.    Note that as of XEmacs 19.13 and Emacs 19.30, your Emacs already
  113. comes with `cc-mode' version 4 preconfigured for your use.  You should
  114. be able to safely skip the rest of the setup information in this
  115. chapter.
  116.  
  117.    The first thing you will want to do is put `cc-mode.el' somewhere on
  118. your `load-path' so Emacs can find it.  Do a `C-h v load-path RET' to
  119. see all the directories Emacs looks at when loading a file.  If none of
  120. these directories are appropriate, create a new directory and add it to
  121. your `load-path':
  122.  
  123. *[in the shell]*
  124.  
  125.      % cd
  126.      % mkdir mylisp
  127.      % mv cc-mode.el mylisp
  128.      % cd mylisp
  129.  
  130. *[in your .emacs file add]*
  131.  
  132.      (setq load-path (cons "~/mylisp" load-path))
  133.  
  134.    Next you want to "byte compile" `cc-mode.el'.  The mode uses a lot
  135. of macros so if you don't byte compile it, things will be unbearably
  136. slow.  *You can ignore all byte-compiler warnings!*  They are the
  137. result of the supporting different versions of Emacs, and none of the
  138. warnings have any effect on operation. Let me say this again: *You
  139. really can ignore all byte-compiler warnings!*
  140.  
  141.    Here's what to do to byte-compile the file [in emacs]:
  142.  
  143.      M-x byte-compile-file RET ~/mylisp/cc-mode.el RET
  144.  
  145.    If you are running a version of Emacs or XEmacs that comes with
  146. `cc-mode' by default, you can simply add the following to your `.emacs'
  147. file in order to upgrade to the latest version of `cc-mode':
  148.  
  149.      (load "cc-mode")
  150.  
  151.    Users of even older versions of Emacs 19, Emacs 18, or of the older
  152. Lucid Emacs will probably be running an Emacs that has BOCM `c-mode.el'
  153. and possible `c++-mode.el' pre-dumped.  If your Emacs is dumped with
  154. either of these files you first need to make Emacs "forget" about those
  155. older modes.
  156.  
  157.    If you can do a `C-h v c-mode-map RET' without getting an error, you
  158. need to add these lines at the top of your `.emacs' file:
  159.  
  160.      (fmakunbound 'c-mode)
  161.      (makunbound  'c-mode-map)
  162.      (fmakunbound 'c++-mode)
  163.      (makunbound  'c++-mode-map)
  164.      (makunbound  'c-style-alist)
  165.  
  166.    After those lines you will want to add the following autoloads to
  167. your `.emacs' file so that `cc-mode' gets loaded at the right time:
  168.  
  169.      (autoload 'c++-mode  "cc-mode" "C++ Editing Mode" t)
  170.      (autoload 'c-mode    "cc-mode" "C Editing Mode" t)
  171.      (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t)
  172.      (autoload 'java-mode "cc-mode" "Java Editing Mode" t)
  173.  
  174.    Alternatively, if you want to make sure `cc-mode' is loaded when
  175. Emacs starts up, you could use this line instead of the three autoloads
  176. above:
  177.  
  178.      (require 'cc-mode)
  179.  
  180.    Next, you will want to set up Emacs so that it edits C files in
  181. `c-mode', C++ files in `c++-mode', and Objective-C files in
  182. `objc-mode'. All users should add the following to their `.emacs' file.
  183. Note that this assumes you'll be editing `.h' and `.c' files as C,
  184. `.hh', `.cc', `.H', and `.C' files as C++, `.m' files as Objective-C,
  185. and `.java' files as Java code. YMMV:
  186.  
  187.      (setq auto-mode-alist
  188.        (append
  189.          '(("\\.C$"    . c++-mode)
  190.            ("\\.H$"    . c++-mode)
  191.            ("\\.cc$"   . c++-mode)
  192.            ("\\.hh$"   . c++-mode)
  193.            ("\\.c$"    . c-mode)
  194.            ("\\.h$"    . c-mode)
  195.            ("\\.m$"    . objc-mode)
  196.            ("\\.java$" . java-mode)
  197.           ) auto-mode-alist))
  198.  
  199.    You may already have some or all of these settings on your
  200. `auto-mode-alist', but it won't hurt to put them on there again.
  201.  
  202.    That's all you need - I know, I know, it sounds like a lot `:-)',
  203. but after you've done all this, you should only need to quit and restart
  204. Emacs.  The next time you visit a C, C++, Objective-C, or Java file you
  205. should be using `cc-mode'.  You can check this easily by hitting `M-x
  206. c-version RET' in the `c-mode', `c++-mode', or `objc-mode' buffer.  You
  207. should see this message in the echo area:
  208.  
  209.      Using `cc-mode' version 4.XXX
  210.      
  211.      Where XXX is the latest release minor number.
  212.  
  213. * Menu:
  214.  
  215. * Syntactic Analysis::
  216. * Indentation Calculation::
  217.  
  218. 
  219. File: ccmode,  Node: New Indentation Engine,  Next: Minor Modes,  Prev: Getting Connected,  Up: Top
  220.  
  221. New Indentation Engine
  222. **********************
  223.  
  224.    `cc-mode' has a new indentation engine, providing a simplified, yet
  225. flexible and general mechanism for customizing indentation. It breaks
  226. indentation calculation into two steps. First for the line of code being
  227. indented, `cc-mode' analyzes what kind of language construct it's
  228. looking at, then it applies user defined offsets to the current line
  229. based on this analysis.
  230.  
  231.    This section will briefly cover how indentation is calculated in
  232. `cc-mode'. It is important to understand the indentation model being
  233. used so that you will know how to customize `cc-mode' for your personal
  234. coding style.
  235.  
  236. * Menu:
  237.  
  238. * Syntactic Analysis::
  239. * Indentation Calculation::
  240.  
  241. 
  242. File: ccmode,  Node: Syntactic Analysis,  Next: Indentation Calculation,  Up: New Indentation Engine
  243.  
  244. Syntactic Analysis
  245. ==================
  246.  
  247.    The first thing `cc-mode' does when indenting a line of code, is to
  248. analyze the line, determining the "syntactic component list" of the
  249. construct on that line.  A "syntactic component" consists of a pair of
  250. information (in lisp parlance, a *cons cell*), where the first part is
  251. a "syntactic symbol", and the second part is a "relative buffer
  252. position".  Syntactic symbols describe elements of C code (1), e.g.
  253. `statement', `substatement', `class-open', `class-close', etc.  *Note
  254. Syntactic Symbols::, for a complete list of currently recognized
  255. syntactic symbols and their semantics.  The variable `c-offsets-alist'
  256. also contains the list of currently supported syntactic symbols.
  257.  
  258.    Conceptually, a line of C code is always indented relative to the
  259. indentation of some line higher up in the buffer.  This is represented
  260. by the relative buffer position in the syntactic component.
  261.  
  262.    It might help to see an example. Suppose we had the following code as
  263. the only thing in a `c++-mode' buffer (2):
  264.  
  265.        1: void swap( int& a, int& b )
  266.        2: {
  267.        3:     int tmp = a;
  268.        4:     a = b;
  269.        5:     b = tmp;
  270.        6: }
  271.  
  272.    We can use the command `C-c C-s' (`c-show-syntactic-information') to
  273. simply report what the syntactic analysis is for the current line.
  274. Running this command on line 4 this example, we'd see in the echo area:
  275.  
  276.      ((statement . 35))
  277.  
  278.    This tells us that the line is a statement and it is indented
  279. relative to buffer position 35, which happens to be the `i' in `int' on
  280. line 3.  If you were to move point to line 3 and hit `C-c C-s', you
  281. would see:
  282.  
  283.      ((defun-block-intro . 29))
  284.  
  285.    This indicates that the `int' line is the first statement in a top
  286. level function block, and is indented relative to buffer position 29,
  287. which is the brace just after the function header.
  288.  
  289.    Here's another example:
  290.  
  291.        1: int add( int val, int incr, int doit )
  292.        2: {
  293.        3:     if( doit )
  294.        4:         {
  295.        5:             return( val + incr );
  296.        6:         }
  297.        7:     return( val );
  298.        8: }
  299.  
  300. Hitting `C-c C-s' on line 4 gives us:
  301.  
  302.      ((substatement-open . 46))
  303.  
  304. which tells us that this is a brace that *opens* a substatement block.
  305. (3)
  306.  
  307.    Syntactic component lists can contain more than one component, and
  308. individual syntactic components need not have relative buffer positions.
  309. The most common example of this is a line that contains a "comment only
  310. line".
  311.  
  312.        1: void draw_list( List<Drawables>& drawables )
  313.        2: {
  314.        3:         // call the virtual draw() method on each element in list
  315.        4:     for( int i=0; i < drawables.count(), ++i )
  316.        5:     {
  317.        6:         drawables[i].draw();
  318.        7:     }
  319.        8: }
  320.  
  321. Hitting `C-c C-s' on line 3 of example 3 gives us:
  322.  
  323.      ((comment-intro) (defun-block-intro . 46))
  324.  
  325. so you can see that the syntactic component list contains two syntactic
  326. components.  Also notice that the first component, `(comment-intro)'
  327. has no relative buffer position.
  328.  
  329.    ---------- Footnotes ----------
  330.  
  331.    (1)  or C++, Objective-C, or Java code.  In general, for the rest of
  332. this manual I'll use the term "C code" to refer to all the C-like
  333. dialects, unless otherwise noted.
  334.  
  335.    (2)  The line numbers in this and future examples don't actually
  336. appear in the buffer, of course!
  337.  
  338.    (3)  A "substatement" indicates the line after an `if', `else',
  339. `while', `do', `switch', or `for' statement, and a "substatement block"
  340. is a brace block following one of those constructs.
  341.  
  342. 
  343. File: ccmode,  Node: Indentation Calculation,  Prev: Syntactic Analysis,  Up: New Indentation Engine
  344.  
  345. Indentation Calculation
  346. =======================
  347.  
  348.    Indentation for the current line is calculated using the syntactic
  349. component list derived in step 1 above (see *Note Syntactic Analysis::).
  350. Each component contributes to the final total indentation of the line in
  351. two ways.
  352.  
  353.    First, the syntactic symbols are looked up in the `c-offsets-alist'
  354. variable, which is an association list of syntactic symbols and the
  355. offsets to apply for those symbols.  These offsets are added to the
  356. running total.
  357.  
  358.    Second, if the component has a relative buffer position, `cc-mode'
  359. adds the column number of that position to the running total.  By adding
  360. up the offsets and columns for every syntactic component on the list,
  361. the final total indentation for the current line is computed.
  362.  
  363.    Let's use our two code examples above to see how this works.  Here is
  364. our first example again:
  365.  
  366.          1: void swap( int& a, int& b )
  367.          2: {
  368.          3:     int tmp = a;
  369.          4:     a = b;
  370.          5:     b = tmp;
  371.          6: }
  372.  
  373.    Let's say point is on line 3 and we hit the TAB key to re-indent the
  374. line.  Remember that the syntactic component list for that line is:
  375.  
  376.      ((defun-block-intro . 29))
  377.  
  378. `cc-mode' looks up `defun-block-intro' in the `c-offsets-alist'
  379. variable.  Let's say it finds the value `4'; it adds this to the
  380. running total (initialized to zero), yielding a running total
  381. indentation of 4 spaces.
  382.  
  383.    Next `cc-mode' goes to buffer position 29 and asks for the current
  384. column.  Since the brace at buffer position 29 is in column zero, it
  385. adds `0' to the running total.  Since there is only one syntactic
  386. component on the list for this line, indentation calculation is
  387. complete, and the total indentation for the line is 4 spaces.
  388.  
  389.    Here's another example:
  390.  
  391.          1: int add( int val, int incr, int doit )
  392.          2: {
  393.          3:     if( doit )
  394.          4:         {
  395.          5:             return( val + incr );
  396.          6:         }
  397.          7:     return( val );
  398.          8: }
  399.  
  400.    If we were to hit `TAB' on line 4 in the above example, the same
  401. basic process is performed, despite the differences in the syntactic
  402. component list.  Remember that the list for this line is:
  403.  
  404.      ((substatement-open . 46))
  405.  
  406.    Here, `cc-mode' first looks up the `substatement-open' symbol in
  407. `c-offsets-alist'. Let's say it finds the value `4'.  This yields a
  408. running total of 4.  `cc-mode' then goes to buffer position 46, which
  409. is the `i' in `if' on line 3.  This character is in the fourth column
  410. on that line so adding this to the running total yields an indentation
  411. for the line of 8 spaces.
  412.  
  413.    Simple, huh?
  414.  
  415.    Actually, the mode usually just does The Right Thing without you
  416. having to think about it in this much detail.  But when customizing
  417. indentation, it's helpful to understand the general indentation model
  418. being used.
  419.  
  420.    To help you configure `cc-mode', you can set the variable
  421. `c-echo-syntactic-information-p' to non-`nil' so that the syntactic
  422. component list and calculated offset will always be echoed in the
  423. minibuffer when you hit `TAB'.
  424.  
  425. 
  426. File: ccmode,  Node: Minor Modes,  Next: Indentation Commands,  Prev: New Indentation Engine,  Up: Top
  427.  
  428. Minor Modes
  429. ***********
  430.  
  431.    `cc-mode' contains two minor-mode-like features that you should find
  432. useful while you enter new C code.  The first is called "auto-newline"
  433. mode, and the second is called "hungry-delete" mode.  These minor modes
  434. can be toggled on and off independently, and `cc-mode' can be
  435. configured so that it comes up with any combination of these minor
  436. modes.  By default, both of these minor modes are turned off.
  437.  
  438.    The state of the minor modes is always reflected in the minor mode
  439. list on the modeline of the `cc-mode' buffer.  When auto-newline mode is
  440. enabled, you will see `C/a' on the mode line (1).  When hungry delete
  441. mode is enabled you would see `C/h' and when both modes are enabled,
  442. you'd see `C/ah'.
  443.  
  444.    `cc-mode' provides keybindings which allow you to toggle the minor
  445. modes while editing code on the fly.  To toggle just the auto-newline
  446. state, hit `C-c C-a' (`c-toggle-auto-state').  When you do this, you
  447. should see the `a' indicator either appear or disappear on the
  448. modeline.  Similarly, to toggle just the hungry-delete state, use `C-c
  449. C-d' (`c-toggle-hungry-state'), and to toggle both states together, use
  450. `C-c C-t' (`c-toggle-auto-hungry-state').
  451.  
  452.    To set up the auto-newline and hungry-delete states to your preferred
  453. values, you would need to add some lisp to your `.emacs' file that
  454. called one of the `c-toggle-*-state' functions directly.  When called
  455. programmatically, each function takes a numeric value, where a positive
  456. number enables the minor mode, a negative number disables the mode, and
  457. zero toggles the current state of the mode.
  458.  
  459.    So for example, if you wanted to enable both auto-newline and
  460. hungry-delete for all your C file editing, you could add the following
  461. to your `.emacs' file:
  462.  
  463.      (add-hook 'c-mode-common-hook '(lambda () (c-toggle-auto-hungry-state 1)))
  464.  
  465. * Menu:
  466.  
  467. * Auto-newline insertion::
  468. * Hungry-deletion of whitespace::
  469.  
  470.    ---------- Footnotes ----------
  471.  
  472.    (1)  Remember that the `C' would be replaced with `C++' or `ObjC' if
  473. you were editing C++ or Objective-C code.
  474.  
  475. 
  476. File: ccmode,  Node: Auto-newline insertion,  Next: Hungry-deletion of whitespace,  Up: Minor Modes
  477.  
  478. Auto-newline insertion
  479. ======================
  480.  
  481.    Auto-newline minor mode works by enabling certain "electric
  482. commands".  Electric commands are typically bound to special characters
  483. such as the left and right braces, colons, semi-colons, etc., which when
  484. typed, perform some magic formatting in addition to inserting the typed
  485. character.  As a general rule, electric commands are only electric when
  486. the following conditions apply:
  487.  
  488.    * Auto-newline minor mode is enabled, as evidenced by a `C/a' or
  489.      `C/ah' indicator on the modeline.
  490.  
  491.    * The character was not typed inside of a literal (1).
  492.  
  493.    * No numeric argument was supplied to the command (i.e. it was typed
  494.      as normal, with no `C-u' prefix).
  495.  
  496.    Certain other conditions may apply on a language specific basis.  For
  497. example, the second slash (`/') of a C++ style line comment is electric
  498. in `c++-mode', `objc-mode', and `java-mode', but not in `c-mode'.
  499.  
  500. * Menu:
  501.  
  502. * Hanging Braces::
  503. * Hanging Colons::
  504. * Hanging Semi-colons and commas::
  505. * Other electric commands::
  506. * Clean-ups::
  507.  
  508.    ---------- Footnotes ----------
  509.  
  510.    (1)  A "literal" is defined in `cc-mode' as any comment, string, or
  511. cpp macro definition.  These constructs are also known as "syntactic
  512. whitespace" since they are usually ignored when scanning C code.
  513.  
  514. 
  515. File: ccmode,  Node: Hanging Braces,  Next: Hanging Colons,  Up: Auto-newline insertion
  516.  
  517. Hanging Braces
  518. --------------
  519.  
  520.    When you type either an open or close brace (i.e. `{' or `}'), the
  521. electric command `c-electric-brace' gets run.  This command has two
  522. electric formatting behaviors.  First, it will perform some
  523. re-indentation of the line the brace was typed on, and second, it will
  524. add various newlines before and/or after the typed brace.
  525. Re-indentation occurs automatically whenever the electric behavior is
  526. enabled.  If the brace ends up on a line other than the one it was typed
  527. on, then that line is on is also indented according to
  528. `c-offsets-alist'.
  529.  
  530.    The insertion of newlines is controlled by the
  531. `c-hanging-braces-alist' variable.  This variable contains a mapping
  532. between syntactic symbols related to braces, and a list of places to
  533. insert a newline.  The syntactic symbols that are useful for this list
  534. are: `class-open', `class-close', `defun-open', `defun-close',
  535. `inline-open', `inline-close', `brace-list-open', `brace-list-close',
  536. `brace-list-intro', `brace-list-entry', `block-open', `block-close',
  537. `substatement-open', and `statement-case-open'.  *Note Syntactic
  538. Symbols:: for a more detailed description of these syntactic symbols.
  539.  
  540.    The value associated with each syntactic symbol in this association
  541. list is called an ACTION which can be either a function or a list.
  542. *Note Custom Brace and Colon Hanging:: for a more detailed discussion of
  543. using a function as a brace hanging ACTION.
  544.  
  545.    When ACTION is a list, it can contain any combination of the symbols
  546. `before' or `after', directing `cc-mode' where to put newlines in
  547. relationship to the brace being inserted.  Thus, if the list contains
  548. only the symbol `after', then the brace is said to "hang" on the right
  549. side of the line, as in:
  550.  
  551.      // here, open braces always `hang'
  552.      void spam( int i ) {
  553.          if( i == 7 ) {
  554.              dosomething(i);
  555.          }
  556.      }
  557.  
  558.    When the list contains both `after' and `before', the braces will
  559. appear on a line by themselves, as shown by the close braces in the
  560. above example.  The list can also be empty, in which case no newlines
  561. are added either before or after the brace.
  562.  
  563.    For example, the default value of `c-hanging-braces-alist' is:
  564.  
  565.      (defvar c-hanging-braces-alist '((brace-list-open)
  566.                                       (substatement-open after)
  567.                                       (block-close . c-snug-do-while)))
  568.  
  569. which says that `brace-list-open' braces should both hang on the right
  570. side, and allow subsequent text to follow on the same line as the
  571. brace.  Also, `substatement-open' braces should hang on the right side,
  572. but subsequent text should follow on the next line.  Here, in the
  573. `block-close' entry, you also see an example of using a function as an
  574. ACTION.
  575.  
  576. 
  577. File: ccmode,  Node: Hanging Colons,  Next: Hanging Semi-colons and commas,  Prev: Hanging Braces,  Up: Auto-newline insertion
  578.  
  579. Hanging Colons
  580. --------------
  581.  
  582.    Using a mechanism similar to brace hanging (see *Note Hanging
  583. Braces::), colons can also be made to hang using the variable
  584. `c-hanging-colons-alist'.  The syntactic symbols appropriate for this
  585. association list are: `case-label', `label', `access-label',
  586. `member-init-intro', and `inher-intro'.  *Note Hanging Braces:: and
  587. *Note Custom Brace and Colon Hanging:: for details.  Note however, that
  588. `c-hanging-colons-alist' does not implement functions as ACTIONs.
  589.  
  590.    In C++, double-colons are used as a scope operator but because these
  591. colons always appear right next to each other, newlines before and after
  592. them are controlled by a different mechanism, called "clean-ups" in
  593. `cc-mode'.  *Note Clean-ups:: for details.
  594.  
  595. 
  596. File: ccmode,  Node: Hanging Semi-colons and commas,  Next: Other electric commands,  Prev: Hanging Colons,  Up: Auto-newline insertion
  597.  
  598. Hanging Semi-colons and commas
  599. ------------------------------
  600.  
  601.    Semicolons and commas are also electric in `cc-mode', but since
  602. these characters do not correspond directly to syntactic symbols, a
  603. different mechanism is used to determine whether newlines should be
  604. automatically inserted after these characters.  *Note Customizing
  605. Semi-colons and Commas:: for details.
  606.  
  607. 
  608. File: ccmode,  Node: Other electric commands,  Next: Clean-ups,  Prev: Hanging Semi-colons and commas,  Up: Auto-newline insertion
  609.  
  610. Other electric commands
  611. -----------------------
  612.  
  613.    A few other keys also provide electric behavior.  For example the
  614. `#' key (`c-electric-pound') is electric when it is typed as the first
  615. non-whitespace character on a line.  In this case, the variable
  616. `c-electric-pound-behavior' is consulted for the electric behavior.
  617. This variable takes a list value, although the only element currently
  618. defined is `alignleft', which tells this command to force the `#'
  619. character into column zero.  This is useful for entering cpp macro
  620. definitions.
  621.  
  622.    Stars and slashes (i.e. `*' and `/') are also electric under certain
  623. circumstances.  If a star is inserted as the second character of a C
  624. style block comment on a "comment-only" line, then the comment
  625. delimiter is indented as defined by `c-offsets-alist'.  A comment-only
  626. line is defined as a line which contains only a comment, as in:
  627.  
  628.      void spam( int i )
  629.      {
  630.              // this is a comment-only line...
  631.          if( i == 7 )                             // but this is not
  632.          {
  633.              dosomething(i);
  634.          }
  635.      }
  636.  
  637.    Likewise, if a slash is inserted as the second slash in a C++ style
  638. line comment (also only on a comment-only line), then the line is
  639. indented as defined by `c-offsets-alist'.
  640.  
  641. 
  642. File: ccmode,  Node: Clean-ups,  Prev: Other electric commands,  Up: Auto-newline insertion
  643.  
  644. Clean-ups
  645. ---------
  646.  
  647.    "Clean-ups" are a mechanism complementary to colon and brace
  648. hanging.  On the surface, it would seem that clean-ups overlap the
  649. functionality provided by the `c-hanging-*-alist' variables, and
  650. similarly, clean-ups are only enabled when auto-newline minor mode is
  651. enabled.  Clean-ups are used however to adjust code "after-the-fact",
  652. i.e. to eliminate some whitespace that isn't inserted by electric
  653. commands, or whitespace that contains intervening constructs.
  654.  
  655.    You can configure `cc-mode''s clean-ups by setting the variable
  656. `c-cleanup-list', which is a list of clean-up symbols.  By default,
  657. `cc-mode' cleans up only the `scope-operator' construct, which is
  658. necessary for proper C++ support.  Note that clean-ups are only
  659. performed when the construct does not occur within a literal (see *Note
  660. Auto-newline insertion::), and when there is nothing but whitespace
  661. appearing between the individual components of the construct.
  662.  
  663.    There are currently only five specific constructs that `cc-mode' can
  664. clean up, as indicated by these symbols:
  665.  
  666.    * `brace-else-brace' - cleans up `} else {' constructs by placing
  667.      the entire construct on a single line.  Clean-up occurs when the
  668.      open brace after the `else' is typed.  So for example, this:
  669.  
  670.           void spam(int i)
  671.           {
  672.               if( i==7 )
  673.               {
  674.                   dosomething();
  675.               }
  676.               else
  677.               {
  678.  
  679.      appears like this after the open brace is typed:
  680.  
  681.           void spam(int i)
  682.           {
  683.               if( i==7 ) {
  684.                   dosomething();
  685.               } else {
  686.  
  687.    * `empty-defun-braces' - cleans up braces following a top-level
  688.      function or class definition that contains no body.  Clean up
  689.      occurs when the closing brace is typed.  Thus the following:
  690.  
  691.           class Spam
  692.           {
  693.           }
  694.  
  695.      is transformed into this when the close brace is typed:
  696.  
  697.           class Spam
  698.           {}
  699.  
  700.    * `defun-close-semi' - cleans up the terminating semi-colon on
  701.      top-level function or class definitions when they follow a close
  702.      brace. Clean up occurs when the semi-colon is typed.  So for
  703.      example, the following:
  704.  
  705.           class Spam
  706.           {
  707.           }
  708.           ;
  709.  
  710.      is transformed into this when the semi-colon is typed:
  711.  
  712.  
  713.           class Spam
  714.           {
  715.           };
  716.  
  717.    * `list-close-comma' - cleans up commas following braces in array
  718.      and aggregate initializers.  Clean up occurs when the comma is
  719.      typed.
  720.  
  721.    * `scope-operator' - cleans up double colons which may designate a
  722.      C++ scope operator split across multiple lines(1).  Clean up
  723.      occurs when the second colon is typed.  You will always want
  724.      `scope-operator' in the `c-cleanup-list' when you are editing C++
  725.      code.
  726.  
  727.    ---------- Footnotes ----------
  728.  
  729.    (1)  Certain C++ constructs introduce ambiguous situations, so
  730. `scope-operator' clean-ups may not always be correct.  This usually
  731. only occurs when scoped identifiers appear in switch label tags.
  732.  
  733. 
  734. File: ccmode,  Node: Hungry-deletion of whitespace,  Prev: Auto-newline insertion,  Up: Minor Modes
  735.  
  736. Hungry-deletion of whitespace
  737. =============================
  738.  
  739.    Hungry deletion of whitespace, or as it more commonly called,
  740. "hungry-delete mode", is a simple feature that some people find
  741. extremely useful.  In fact, you might find yourself wanting
  742. hungry-delete in *all* your editing modes!
  743.  
  744.    In a nutshell, when hungry-delete mode is enabled, hitting the `DEL'
  745. character will consume all preceding whitespace, including newlines and
  746. tabs.  This can really cut down on the number of `DEL''s you have to
  747. type if, for example you made a mistake on the preceding line.
  748.  
  749.    By default, `cc-mode' actually runs the command `c-electric-delete'
  750. when you hit `DEL'.  When this command is used to delete a single
  751. character (i.e. when it is called interactively with no numeric
  752. argument), it really runs the function contained in the variable
  753. `c-delete-function'.  This function is called with a single argument,
  754. which is the number of characters to delete.  `c-delete-function' is
  755. also called when the `DEL' key is typed inside a literal (see *Note
  756. Auto-newline insertion::.  Inside a literal, `c-electric-delete' is not
  757. electric, which is typical of all the so-called electric commands.
  758.  
  759. 
  760. File: ccmode,  Node: Indentation Commands,  Next: Customizing Indentation,  Prev: Minor Modes,  Up: Top
  761.  
  762. Indentation Commands
  763. ********************
  764.  
  765.    Various commands are provided which allow you to conveniently
  766. re-indent C constructs, and these are outlined below.  There are
  767. several things to note about these indentation commands.  First, when
  768. you change your programming style, either though `c-set-style' or some
  769. other means, your file does *not* automatically get re-indented.  When
  770. you change style parameters, you will typically need to reformat the
  771. line, expression, or buffer to see the effects of your changes.
  772.  
  773.    Second, changing some variables have no effect on existing code, even
  774. when you do re-indent.  For example, the `c-hanging-*' variables and
  775. `c-cleanup-list' only affect newly entered code.  So for example,
  776. changing `c-hanging-braces-alist' and re-indenting the buffer will not
  777. adjust placement of braces already in the file.
  778.  
  779.    Third, re-indenting large portions of code is currently rather
  780. inefficient.  Improvements have been made since previous releases of
  781. `cc-mode', and much more radical improvements will be made for the next
  782. release, but for now you need to be aware of this (1).  Some provision
  783. has been made to at least inform you as to the progress of your large
  784. re-indentation command.  The variable `c-progress-interval' controls
  785. how often a progress message is displayed.  Set this variable to `nil'
  786. to inhibit progress messages.  Note that this feature only works with
  787. Emacs 19.
  788.  
  789.    Also, except as noted below, re-indentation is always driven by the
  790. same mechanisms that control on-the-fly indentation of code.  *Note New
  791. Indentation Engine:: for details.
  792.  
  793.    To indent a single line of code, use `TAB' (`c-indent-command').
  794. The behavior of this command is controlled by the variable
  795. `c-tab-always-indent'.  When this variable is `t', `TAB' always just
  796. indents the current line.  When `nil', the line is indented only if
  797. point is at the left margin, or on or before the first non-whitespace
  798. character on the line, otherwise a real tab character is inserted.  If
  799. this variable's value is something other that `t' or `nil' (e.g.
  800. `'other'), then a real tab character is inserted only when point is
  801. inside a literal (see *Note Auto-newline insertion::), otherwise the
  802. line is indented.
  803.  
  804.    To indent an entire balanced brace or parenthesis expression, use
  805. `M-C-q' (`c-indent-exp').  Note that point should be on the opening
  806. brace or parenthesis of the expression you want to indent.
  807.  
  808.    Another very convenient keystroke is `C-c C-q' (`c-indent-defun')
  809. when re-indents the entire top-level function or class definition that
  810. encompasses point.  It leaves point at the same position within the
  811. buffer.
  812.  
  813.    To indent any arbitrary region of code, use `M-C-\'
  814. (`indent-region').   This is a standard Emacs command, specially
  815. tailored for C code in a `cc-mode' buffer.  Note that of course, point
  816. and mark must delineate the region you want to indent.
  817.  
  818.    While not strictly an indentation function, `M-C-h'
  819. (`c-mark-function') is useful for marking the current top-level
  820. function or class definition as the current region.
  821.  
  822.    ---------- Footnotes ----------
  823.  
  824.    (1)  In particular, I have had people complain about the speed that
  825. `cc-mode' re-indents `lex(1)' output.  Lex, yacc, and other code
  826. generators usually output some pretty perverse code.  *Don't* try to
  827. indent this stuff with `cc-mode'!
  828.  
  829. 
  830. File: ccmode,  Node: Customizing Indentation,  Next: Syntactic Symbols,  Prev: Indentation Commands,  Up: Top
  831.  
  832. Customizing Indentation
  833. ***********************
  834.  
  835.    The `c-offsets-alist' variable is where you customize all your
  836. indentations.  You simply need to decide what additional offset you want
  837. to add for every syntactic symbol.  You can use the command `C-c C-o'
  838. (`c-set-offset') as the way to set offsets, both interactively and from
  839. your mode hook.  Also, you can set up *styles* of indentation just like
  840. in BOCM.  Most likely, you'll find one of the pre-defined styles will
  841. suit your needs, but if not, this section will describe how to set up
  842. basic editing configurations.  *Note Styles:: for an explanation of how
  843. to set up named styles.
  844.  
  845.    As mentioned previously, the variable `c-offsets-alist' is an
  846. association list between syntactic symbols and the offsets to be applied
  847. for those symbols.  In fact, these offset values can be an integer, a
  848. function or variable name, or one of the following symbols: `+', `-',
  849. `++', `--', `*', or `/'.  These symbols describe offset in multiples of
  850. the value of the variable `c-basic-offset'.  By defining a style's
  851. indentation in terms of this fundamental variable, you can change the
  852. amount of whitespace given to an indentation level while leaving the
  853. same relationship between levels.  Here are multiples of
  854. `c-basic-offset' that the special symbols correspond to:
  855.  
  856.    * `+ ' =  `c-basic-offset' times 1
  857.  
  858.    * `- ' =  `c-basic-offset' times -1
  859.  
  860.    * `++' =  `c-basic-offset' times 2
  861.  
  862.    * `--' =  `c-basic-offset' times -2
  863.  
  864.    * `* ' =  `c-basic-offset' times 0.5
  865.  
  866.    * `/ ' =  `c-basic-offset' times -0.5
  867.  
  868. So, for example, because most of the default offsets are defined in
  869. terms of `+', `-', and `0', if you like the general indentation style,
  870. but you use 4 spaces instead of 2 spaces per level, you can probably
  871. achieve your style just by changing `c-basic-offset' like so (in your
  872. `.emacs' file)(1):
  873.  
  874.      (setq-default c-basic-offset 4)
  875.  
  876. This would change
  877.  
  878.      int add( int val, int incr, int doit )
  879.      {
  880.          if( doit )
  881.              {
  882.                  return( val + incr );
  883.              }
  884.          return( val );
  885.      }
  886.  
  887. to
  888.  
  889.      int add( int val, int incr, int doit )
  890.      {
  891.        if( doit )
  892.          {
  893.            return( val + incr );
  894.          }
  895.        return( val );
  896.      }
  897.  
  898.    To change indentation styles more radically, you will want to change
  899. the value associated with the syntactic symbols in the
  900. `c-offsets-alist' variable.  First, I'll show you how to do that
  901. interactively, then I'll describe how to make changes to your `.emacs'
  902. file so that your changes are more permanent.
  903.  
  904. * Menu:
  905.  
  906. * Interactive Customization::
  907. * Permanent Customization::
  908. * Styles::
  909. * Advanced Customizations::
  910.  
  911.    ---------- Footnotes ----------
  912.  
  913.    (1)  The reason you need to use `setq-default' instead of `setq' is
  914. that `c-basic-offset' is a buffer local variable, as are most of the
  915. `cc-mode' configuration variables.  If you were to put this code in,
  916. e.g. your `c-mode-common-hook' function, you could use `setq'.
  917.  
  918. 
  919. File: ccmode,  Node: Interactive Customization,  Next: Permanent Customization,  Up: Customizing Indentation
  920.  
  921. Interactive Customization
  922. =========================
  923.  
  924.    As an example of how to customize indentation, let's change the
  925. style of example 2 above from:
  926.  
  927.      1: int add( int val, int incr, int doit )
  928.      2: {
  929.      3:     if( doit )
  930.      4:         {
  931.      5:             return( val + incr );
  932.      6:         }
  933.      7:     return( val );
  934.      8: }
  935.  
  936. to:
  937.  
  938.      1: int add( int val, int incr, int doit )
  939.      2: {
  940.      3:     if( doit )
  941.      4:     {
  942.      5:         return( val + incr );
  943.      6:     }
  944.      7:     return( val );
  945.      8: }
  946.  
  947.    In other words, we want to change the indentation of braces that
  948. open a block following a condition so that the braces line up under the
  949. conditional, instead of being indented.  Notice that the construct we
  950. want to change starts on line 4.  To change the indentation of a line,
  951. we need to see which syntactic component affect the offset calculations
  952. for that line.  Hitting `C-c C-s' on line 4 yields:
  953.  
  954.      ((substatement-open . 46))
  955.  
  956. so we know that to change the offset of the open brace, we need to
  957. change the indentation for the `substatement-open' syntactic symbol.
  958. To do this interactively, just hit `C-c C-o' (`c-set-offset').  This
  959. prompts you for the syntactic symbol to change, providing a reasonable
  960. default.  In this case, the default is `substatement-open', which is
  961. just the syntactic symbol we want to change!
  962.  
  963.    After you hit return, `cc-mode' will then prompt you for the new
  964. offset value, with the old value as the default.  The default in this
  965. case is `+', so hit backspace to delete the `+', then hit `0' and
  966. `RET'.  This will associate the offset 0 with the syntactic symbol
  967. `substatement-open' in the `c-offsets-alist' variable.
  968.  
  969.    To check your changes quickly, just hit `C-c C-q' (`c-indent-defun')
  970. to reindent the entire function.  The example should now look like:
  971.  
  972.      1: int add( int val, int incr, int doit )
  973.      2: {
  974.      3:     if( doit )
  975.      4:     {
  976.      5:         return( val + incr );
  977.      6:     }
  978.      7:     return( val );
  979.      8: }
  980.  
  981.    Notice how just changing the open brace offset on line 4 is all we
  982. needed to do.  Since the other affected lines are indented relative to
  983. line 4, they are automatically indented the way you'd expect.  For more
  984. complicated examples, this may not always work.  The general approach to
  985. take is to always start adjusting offsets for lines higher up in the
  986. file, then re-indent and see if any following lines need further
  987. adjustments.
  988.  
  989. 
  990. File: ccmode,  Node: Permanent Customization,  Next: Styles,  Prev: Interactive Customization,  Up: Customizing Indentation
  991.  
  992. Permanent Indentation
  993. =====================
  994.  
  995.    To make this change permanent, you need to add some lisp code to your
  996. `.emacs' file.  `cc-mode' provides four hooks that you can use to
  997. customize your language editing styles.  Four language specific hooks
  998. are provided, according to Emacs major mode conventions: `c-mode-hook',
  999. `c++-mode-hook', `objc-mode-hook', and `java-mode-hook'.  These get run
  1000. as the last thing when you enter `c-mode', `c++-mode', `objc-mode', or
  1001. `java-mode-hook' respectively.  `cc-mode' also provides a hook called
  1002. `c-mode-common-hook' which is run by all three modes *before* the
  1003. language specific hook.  Thus, to make changes consistently across all
  1004. supported `cc-mode' modes, use `c-mode-common-hook'.  Most of the
  1005. examples in this section will assume you are using the common hook.
  1006.  
  1007.    Here's a simplified example of what you can add to your `.emacs'
  1008. file to make the changes described in the previous section (*Note
  1009. Interactive Customization::) more permanent.  See the Emacs manuals for
  1010. more information on customizing Emacs via hooks.  *Note Sample .emacs
  1011. File:: for a more complete sample `.emacs' file.  (1)
  1012.  
  1013.      (defun my-c-mode-common-hook ()
  1014.        ;; my customizations for all of c-mode, c++-mode, objc-mode, java-mode
  1015.        (c-set-offset 'substatement-open 0)
  1016.        ;; other customizations can go here
  1017.        )
  1018.      (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  1019.  
  1020.    For complex customizations, you will probably want to set up a
  1021. *style* that groups all your customizations under a single name.
  1022.  
  1023.    The offset value can also be a function, and this is how power users
  1024. gain enormous flexibility in customizing indentation. *Note Advanced
  1025. Customizations:: for details.
  1026.  
  1027.    ---------- Footnotes ----------
  1028.  
  1029.    (1)  The use of `add-hook' in this example only works for Emacs 19.
  1030. Workarounds are available if you are using Emacs 18.
  1031.  
  1032. 
  1033. File: ccmode,  Node: Styles,  Next: Advanced Customizations,  Prev: Permanent Customization,  Up: Customizing Indentation
  1034.  
  1035. Styles
  1036. ======
  1037.  
  1038.    Most people only need to edit code formatted in just a few
  1039. well-defined and consistent styles.  For example, their organization
  1040. might impose a "blessed" style that all its programmers must conform
  1041. to.  Similarly, people who work on GNU software will have to use the
  1042. GNU coding style on C code.  Some shops are more lenient, allowing some
  1043. variety of coding styles, and as programmers come and go, there could
  1044. be a number of styles in use.  For this reason, `cc-mode' makes it
  1045. convenient for you to set up logical groupings of customizations called
  1046. "styles", associate a single name for any particular style, and pretty
  1047. easily start editing new or existing code using these styles.  This
  1048. chapter describes how to set up styles and how to edit your C code
  1049. using styles.
  1050.  
  1051. * Menu:
  1052.  
  1053. * Built-in Styles::
  1054. * Adding Styles::
  1055. * File Styles::
  1056.  
  1057. 
  1058. File: ccmode,  Node: Built-in Styles,  Next: Adding Styles,  Up: Styles
  1059.  
  1060. Built-in Styles
  1061. ---------------
  1062.  
  1063.    If you're lucky, one of `cc-mode''s built-in styles might be just
  1064. what you're looking for.  Some of the most common C and C++ styles are
  1065. already built-in.  These include:
  1066.  
  1067.    * `gnu' - coding style blessed by the Free Software Foundation for C
  1068.      code in GNU programs.
  1069.  
  1070.    * `k&r' - The classic Kernighan and Ritchie style for C code.
  1071.  
  1072.    * `bsd' - *<TBD> Anybody know anything about the history of this
  1073.      style?*
  1074.  
  1075.    * `stroustrup' - The classic Stroustrup style for C++ code.
  1076.  
  1077.    * `whitesmith' - *<TBD> Anybody know anything about the history of
  1078.      this style?*
  1079.  
  1080.    * `ellemtel' - Popular C++ coding standards as defined by
  1081.      "Programming in C++, Rules and Recommendations", Erik Nyquist and
  1082.      Mats Henricson, Ellemtel (1).
  1083.  
  1084.    * `java' - The style for editing Java code.  Note that this style is
  1085.      automatically installed when you enter `java-mode'.
  1086.  
  1087.    * `CC-MODE' - Style that encapsulates the default values of the
  1088.      `cc-mode' variables.  See below for details.
  1089.  
  1090.    If you'd like to experiment with these built-in styles you can simply
  1091. type the following in a `cc-mode' buffer:
  1092.  
  1093.      `M-x c-set-style RET STYLE-NAME RET'
  1094.  
  1095. Note that all style names are case insensitive, even the ones you
  1096. define.
  1097.  
  1098.    Setting a style in this way does *not* automatically re-indent your
  1099. file.  For commands that you can use to view the effect of your changes,
  1100. see *Note Indentation Commands::.
  1101.  
  1102.    Once you find a built-in style you like, you can make the change
  1103. permanent by adding a call to your `.emacs' file.  Let's say for
  1104. example that you want to use the `ellemtel' style in all your files.
  1105. You would add this:
  1106.  
  1107.      (defun my-c-mode-common-hook ()
  1108.        ;; use Ellemtel style for all C, C++, and Objective-C code
  1109.        (c-set-style "ellemtel")
  1110.        ;; other customizations can go here
  1111.        )
  1112.      (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  1113.  
  1114.    There is one other special style you can use, called `CC-MODE'.
  1115. This is a style that is calculated by `cc-mode' when it starts up.  The
  1116. `CC-MODE' style is also special because all other styles implicitly
  1117. inherit from it; in other words, whenever you set a style, `cc-mode'
  1118. first re-instates the `CC-MODE' style, then applies your new style
  1119. configurations.
  1120.  
  1121.    The `CC-MODE' style exists because once `cc-mode' initializes, it
  1122. institutes the `gnu' style for compatibility with BOCM's defaults.  Any
  1123. customizations you make in mode hooks will be based on the `gnu' style,
  1124. unless you first do a `c-set-style' to `CC-MODE' or some other built-in
  1125. style.
  1126.  
  1127.    ---------- Footnotes ----------
  1128.  
  1129.    (1)  This document is ftp'able from `euagate.eua.ericsson.se'
  1130.  
  1131. 
  1132. File: ccmode,  Node: Adding Styles,  Next: File Styles,  Prev: Built-in Styles,  Up: Styles
  1133.  
  1134. Adding Styles
  1135. -------------
  1136.  
  1137.    If none of the built-in styles is appropriate, you'll probably want
  1138. to add a new style definition.  Styles are kept in the `c-style-alist'
  1139. variable, but you probably won't want to modify this variable directly.
  1140. `cc-mode' provides a function, called `c-add-style', that you can use
  1141. to easily add new styles or update existing styles.  This function
  1142. takes two arguments, a STYLENAME string, and an association list
  1143. DESCRIPTION of style customizations.  If STYLENAME is not already in
  1144. `c-style-alist', the new style is added, otherwise the style already
  1145. associated with STYLENAME is changed to the new DESCRIPTION.  This
  1146. function also takes an optional third argument, which if non-`nil',
  1147. automatically institutes the new style in the current buffer.
  1148.  
  1149.    The sample `.emacs' file provides a concrete example of how a new
  1150. style can be added and automatically set.  *Note Sample .emacs File::.
  1151.  
  1152. 
  1153. File: ccmode,  Node: File Styles,  Prev: Adding Styles,  Up: Styles
  1154.  
  1155. File Styles
  1156. -----------
  1157.  
  1158.    The Emacs manual describes how you can customize certain variables
  1159. on a per-file basis by including a "Local Variable" block at the end of
  1160. the file.  So far, you've only seen a functional interface to
  1161. `cc-mode', which is highly inconvenient for use in a Local Variable
  1162. block.  `cc-mode' provides two variables that make it easier for you to
  1163. customize your style on a per-file basis.
  1164.  
  1165.    The variable `c-file-style' can be set to a style name string as
  1166. described in *Note Built-in Styles::.  When the file is visited,
  1167. `cc-mode' will automatically set the file's style to this style using
  1168. `c-set-style'.
  1169.  
  1170.    Another variable, `c-file-offsets', takes an association list
  1171. similar to what is allowed in `c-offsets-alist'.  When the file is
  1172. visited, `cc-mode' will automatically institute these offsets using
  1173. `c-set-offset'.
  1174.  
  1175.    Note that file style settings (i.e. `c-file-style') are applied
  1176. before file offset settings (i.e. `c-file-offsets').
  1177.  
  1178. 
  1179. File: ccmode,  Node: Advanced Customizations,  Prev: Styles,  Up: Customizing Indentation
  1180.  
  1181. Advanced Customizations
  1182. =======================
  1183.  
  1184.    For most users, `cc-mode' will support their coding styles with very
  1185. little need for customizations.  Usually, one of the standard styles
  1186. defined in `c-style-alist' will do the trick.  At most, perhaps one of
  1187. the syntactic symbol offsets will need to be tweaked slightly, or maybe
  1188. `c-basic-offset' will need to be changed.  However, some styles require
  1189. a more advanced ability for customization, and one of the real
  1190. strengths of `cc-mode' is that the syntactic analysis model provides a
  1191. very flexible framework for customizing indentation. This allows you to
  1192. perform special indentation calculations for situations not handled by
  1193. the mode directly.
  1194.  
  1195. * Menu:
  1196.  
  1197. * Custom Indentation Functions::
  1198. * Custom Brace and Colon Hanging::
  1199. * Customizing Semi-colons and Commas::
  1200. * Other Special Indentations::
  1201.  
  1202.